import type { TableColumn } from '@/components/core/dynamic-table';

export type TableListItem = API.TaskManagementListPageResultItem;
export type TableColumnItem = TableColumn<TableListItem>;

const caseCheckResult = (val) => {
  switch (val) {
    case 1:
      return '合格';
    case 2:
      return '不合格';
    default:
      return '-';
  }
};

const caseTaskStatus = (val) => {
  switch (val) {
    case 1:
      return '未开始';
    case 2:
      return '进行中';
    case 4:
      return '待处理';
    case 5:
      return '已结束';
    default:
      return '-';
  }
};

const caseTextColor = (val) => {
  switch (val) {
    case 1:
      return 'color: #999999';
    case 2:
      return 'color: #1677FF';
    case 4:
      return 'color: #F5820F';
    case 5:
      return 'color: #09B840';
    default:
      return 'color: #999999';
  }
};

const checkName = (checkerName, organizerName) => {
  if (checkerName && organizerName) {
    return checkerName + '，' + organizerName;
  } else if (checkerName == '') {
    return organizerName;
  } else if (organizerName == '') {
    return checkerName;
  }
};

export const Taskcolumns: TableColumnItem[] = [
  {
    title: '关键词',
    dataIndex: 'keyword',
    hideInTable: true,
    formItemProps: {
      labelWidth: 55,
      componentProps: () => {
        return {
          placeholder: '请输入任务编号、检查类型',
          autocomplete: 'off',
          disabledLabelWidth: true,
        };
      },
    },
  },
  {
    title: '任务编号',
    align: 'left',
    hideInSearch: true,
    dataIndex: 'taskNo',
  },
  {
    title: '检查类型',
    align: 'left',
    dataIndex: 'checkTypeName',
    hideInSearch: true,
  },
  // {
  //   title: '检查方式',
  //   align: 'left',
  //   dataIndex: 'checkModeName',
  //   hideInSearch: true,
  // },
  {
    title: '当事人类型',
    align: 'left',
    dataIndex: 'partyType',
    hideInSearch: true,
    customRender: ({ record }) => ['自然人', '法人', '个体工商户', '非法人组织'][record.partyType],
  },
  {
    title: '任务状态',
    align: 'left',
    dataIndex: 'taskStatus',
    formItemProps: {
      component: 'Select',
      componentProps: ({ formInstance, formModel, tableInstance }) => ({
        options: [
          {
            label: '全部',
            value: 0,
          },
          {
            label: '未开始',
            value: 1,
          },
          {
            label: '进行中',
            value: 2,
          },
          // {
          //   label: '待判定',
          //   value: 3,
          // },
          {
            label: '待处理',
            value: 4,
          },
          {
            label: '已结束',
            value: 5,
          },
        ],
      }),
      defaultValue: 0,
    },
    customRender: ({ record }) => (
      <div style={caseTextColor(record.taskStatus)}>{caseTaskStatus(record.taskStatus)}</div>
    ),
  },
  {
    title: '结果判定',
    align: 'left',
    dataIndex: 'checkResult',
    formItemProps: {
      component: 'Select',
      componentProps: ({ formInstance, formModel, tableInstance }) => ({
        options: [
          {
            label: '全部',
            value: 0,
          },
          {
            label: '合格',
            value: 1,
          },
          {
            label: '不合格',
            value: 2,
          },
        ],
      }),
      defaultValue: 0,
    },
    customRender: ({ record }) => caseCheckResult(record.checkResult),
  },
  {
    title: '检查人',
    align: 'left',
    dataIndex: 'checkerName',
    hideInSearch: true,
    customRender: ({ record }) => checkName(record.checkerName, record.organizerName),
  },
  {
    title: '检查时间',
    align: 'left',
    dataIndex: 'endCheckTime',
    hideInSearch: true,
  },
];
